﻿IF EXISTS (SELECT * from sys.procedures p left join sys.schemas s on p.schema_id = s.schema_id where p.name='account_select_all' and s.name='Crm')
DROP PROCEDURE [Crm].account_select_all
GO
CREATE PROCEDURE [Crm].account_select_all 
AS
BEGIN
SELECT 	
	[Accounts].[id_account] AS [PK],
	[Accounts].[id_category] AS [CategoryID],
	[Accounts].[name] AS [Name],
	[Accounts].[address] AS [Address],
	[Accounts].[zip_code] AS [ZipCode],
	[Accounts].[city] AS [City],
	[Accounts].[country] AS [Country],
	[Accounts].[url] AS [Url],
	[Accounts].[comment] AS [Comment],
	[Meta].[References].[last_update] AS [LastUpdate],
	[Meta].[References].[Google] AS [Google],
	[Meta].[References].[Google_last_update] AS [GoogleLastUpdate],
	[Meta].[References].[ZohoCRM] AS [ZohoCRM],
	[Meta].[References].[ZohoCRM_last_update] AS [ZohoCRMLastUpdate],
	[Meta].[References].[from] AS [From],
	[Meta].[References].[Validated] AS [Validated]
FROM 
	[Accounts] 
    INNER JOIN [Meta].[References] ON  [Accounts].[id_account] = [References].[id_reference] 
END